package cn.highhand.javalearn.serialize;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Date;

public class JavaDefaultSerialize {
    public static void main(String[] args) throws Exception {



//        serializeObj();
//        deSerializeObj();



    }


    public static void serializeObj() throws  Exception{
        FileOutputStream fos = new FileOutputStream("tmp/t.tmp");
        ObjectOutputStream oos = new ObjectOutputStream(fos);

        oos.writeInt(12345);
        oos.writeObject("Today");
        oos.writeObject(new Date());



        oos.close();
    }

    public static void deSerializeObj() throws  Exception{
        FileInputStream fis = new FileInputStream("tmp/t.tmp");
        ObjectInputStream ois = new ObjectInputStream(fis);

        int i = ois.readInt();
        String today = (String) ois.readObject();
        Date date = (Date) ois.readObject();

        System.out.println(i);
        System.out.println(today);
        System.out.println(date);


        ois.close();
    }
}
